package org.jeecg.modules.sso.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.modules.shiro.authc.ShiroRealm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author jay_liu
 * @since 2019-06-27
 */
@RestController
@RequestMapping("/api")
@Api(tags="获取信息")
@Slf4j
public class GetUserController {
	@Autowired
	private ShiroRealm shiroRealm;

	@RequestMapping(value = "/user", method = RequestMethod.GET)
	@ApiOperation("登录接口")
	public Result<Object> get(HttpServletRequest request) {
		String username = JwtUtil.getUserNameByToken(request);
		try {
			return Result.ok(  shiroRealm.getUser(username));
		} catch (Exception e) {
			log.info("getUserInfo", e);
			return Result.error(504, e.getMessage());
		}
	}

}
